package cn.wolfcode.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.stereotype.Component;

import java.lang.reflect.Array;
import java.util.Date;
import java.util.Map;

@Component
public class JWTUtil {
   private static String signingKey="genshen";
   private static Date expiration=new Date(System.currentTimeMillis()+(1000*3600*24));

    public static String getToken(Map<String,Object> map)
    {
       return Jwts.builder()
               .addClaims(map)
               .signWith(SignatureAlgorithm.HS256,signingKey)
               .setExpiration(expiration)
               .compact();

    }
    public  static Claims  parseToken(String token)
    {
     return    Jwts.parser()
                .setSigningKey(signingKey)
                .parseClaimsJws(token)
                .getBody();
    }
}